package com.example.naodian.controller;


import com.example.naodian.domain.po.EegDataBlock;
import com.example.naodian.domain.po.Warning;
import com.example.naodian.result.Result;
import com.example.naodian.service.IWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 预警信息表 前端控制器
 * </p>
 *
 * @author icewx
 * @since 2025-04-17
 */
@RestController
@RequestMapping("/warning")
@Api(tags = "警告相关接口")
@Slf4j
@AllArgsConstructor
@CrossOrigin(origins = "*") // 允许所有域名跨域请求
public class WarningController {
    private IWarningService warningService;

    /**
     * 根据预警类型或时间搜索预警信息
     * @param type
     * @param date
     * @return 信息集合
     */
    @ApiOperation("根据预警类型或时间搜索预警信息")
    @GetMapping("/list")
    public Result<List<Warning>> getListByTypeAndTime(@Param("type") Integer type,
                                                      @Param("date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        List<Warning> warningList = warningService.getListByTypeAndTime(type, date);
        return Result.success(warningList);
    }

    /**
     * 根据预警id查询相关点位信息
     * @param id
     * @return
     */
    @ApiOperation("根据预警id查询相关点位信息")
    @GetMapping("/{id}")
    public Result<List<EegDataBlock>> getEegDataBlockById(@PathVariable Long id){
        List<EegDataBlock> eegDataBlockList = warningService.getEegDataBlockById(id);
        return Result.success(eegDataBlockList);
    }
}
